Skip to content

Fix aggregate metrics returning 0/0.0 instead of None for empty result sets#2037

Open
dudanogueira wants to merge 2 commits into
weaviate:mainfrom
dudanogueira:fix/aggregate-empty-result-none-values
Open

Fix aggregate metrics returning 0/0.0 instead of None for empty result sets#2037
dudanogueira wants to merge 2 commits into
weaviate:mainfrom
dudanogueira:fix/aggregate-empty-result-none-values

Conversation

@dudanogueira
Copy link
Copy Markdown
Contributor

Fix aggregate metrics returning 0/0.0 instead of None for empty result sets

  • Fixed __parse_property_grpc() to check HasField() before accessing optional protobuf scalars
  • Integer/Number aggregates now correctly return None for unset metrics (maximum, mean, median, minimum, mode, sum_)
  • Date aggregates now correctly return None for unset metrics (maximum, median, minimum, mode)
  • Boolean aggregates now correctly return None for unset metrics (percentage_false, percentage_true, total_false, total_true)
  • Added integration test to verify None values for empty aggregate results
  • Aligns gRPC behavior with GraphQL API behavior

Fixes #2036

…t sets

- Fixed __parse_property_grpc() to check HasField() before accessing optional protobuf scalars
- Integer/Number aggregates now correctly return None for unset metrics (maximum, mean, median, minimum, mode, sum_)
- Date aggregates now correctly return None for unset metrics (maximum, median, minimum, mode)
- Boolean aggregates now correctly return None for unset metrics (percentage_false, percentage_true, total_false, total_true)
- Added integration test to verify None values for empty aggregate results
- Aligns gRPC behavior with GraphQL API behavior

Fixes weaviate#2036
Copy link
Copy Markdown

@orca-security-eu orca-security-eu Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a bug where empty-set aggregate metrics over gRPC returned scalar defaults (0/0.0) instead of None, by gating each optional field read with HasField(). Aligns gRPC behavior with the GraphQL API.

Changes:

  • Use HasField() checks for optional integer/number/boolean/date aggregate metric fields in __parse_property_grpc.
  • Add an integration test confirming None values for empty aggregate result sets.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
weaviate/collections/aggregations/base_executor.py Guard optional protobuf scalar reads with HasField() to preserve unset/None semantics.
integration/test_collection_aggregate.py New integration test verifying integer/number aggregates return None for empty filter results.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python client aggregate.over_all() collapses unset empty-set aggregate metrics to 0/0.0 instead of None

2 participants